<?php $this->load->view('common/header');?>
<?php echo admin_css_url('select2');?>
<?php echo admin_js_url('select2/select2.full.min');?>
<body>
<?php $this->load->view('common/user_center');?>
<div class="main_box">
    <?php $this->load->view('common/menu');?>
    <div class="right_box f_r">
    	<div class="title">
        	<span class="f_l">地址管理</span>
        </div>
        <div class="address_list">
        	<ul>
                <?php if($dress){ ?>
                <?php foreach ($dress as $key => $val) { ?>
            	<li>
                	<span>
                    	<em><?php echo $val['dress_uname'];?>&nbsp;&nbsp;&nbsp;<?php echo $val['dress_utel'];?></em>
                        <p><?php echo $val['dress_city'].$val['dress_udress'];?></p>
                    </span>
                    <a href="javascript:is_dress('<?php echo $val['dress_id']; ?>')" <?php if($key == 0){?>class="on"<?php } ?>>默认地址</a>
                </li>
                    <?php } ?>
                <?php }?>
            </ul>
        </div>
        <div class="title">
        	<span class="f_l">新增地址</span>
        </div>
        <div class="ifrom_list">
            <dl>
            	<dt>收货人：</dt>
                <dd>
                	<span class="input">
                    	<input placeholder="请输入收货人" id="dress_uname" name="dress_uname">
                    </span>
                </dd>
            </dl>
            <dl>
            	<dt>联系电话：</dt>
                <dd>
                	<span class="input">
                    	<input placeholder="请输入联系电话" id="dress_utel" name="dress_utel">
                    </span>
                </dd>
            </dl>
            <dl>
            	<dt>选择地址：</dt>
                <dd>
                    <select name="province_id" id="province_id" class="select form-control select2" size="1">
                        <?php if(isset($province) && !empty($province)){ ?>
                            <?php foreach ($province as $key =>$val ) { ?>
                                <option value="<?php echo $val['area_id'];?>" ><?php echo $val['area_name'];?></option>
                            <?php }?>
                        <?php }?>
                    </select>
                    <select name="city_id" id="city_id" class="select form-control select2" size="1">
                        <option value="0">请选择市</option>
                    </select>
                    <select name="district_id" id="district_id" class="select form-control select2" size="1">
                                <option value="0">请选择区</option>
                    </select>
                </dd>
            </dl>
            <dl>
            	<dt>详细地址：</dt>
                <dd>
                	<span class="input">
                    	<input placeholder="详细街道，门牌号" id="address">
                    </span>
                </dd>
            </dl>
            <dl>
            	<dt>&nbsp;</dt>
                <dd>
                	<a href="javascript:;" id="doModify" class="nav">确定添加</a>
                </dd>
            </dl>
        </div>
    </div>
</div>
<?php echo admin_js_url('area2');?>
<script>
    var ajaxurl = "<?php echo site_url('area/get_area');?>";
    // 提交
    $("#doModify").click(function(){
        var dress_uname      = $("#dress_uname").val();
        var dress_utel      = $("#dress_utel").val();
        var address = $("#address").val();
        var province_id = $("#province_id").val();
        var city_id = $("#city_id").val();
        var district_id = $("#district_id").val();
        // alert(nums);return false;
        if (province_id=="") {
            layer.msg('请选择所在省');
            return false;
        }
        if (city_id=="") {
            layer.msg('请选择所在市');
            return false;
        }
        if (address=="") {
            layer.msg('请填写详细地址');
            return false;
        }
        if (dress_utel=="") {
            layer.msg('请填写填写电话');
            return false;
        }
        var URL= baseurl+"index.php/vip/user/address";
        $.ajax({
            type: "post",
            url: URL,
            dataType:'json',
            data: {
                'dress_uname':dress_uname,
                'dress_utel':dress_utel,
                'address':address,
                'province':province_id,
                'city':city_id,
                'district':district_id,
                'csrf_test_name': ci_csrf_token()
            },
            success: function(data){
                if(data.code == 200){
                    layer.msg(data.msg, {
                        time: 2000, //20s后自动关闭
                    });
                    window.location.href = window.location.href;
                }else{
                    layer.msg(data.msg, {
                        time: 3000, //20s后自动关闭
                    });
                }


            }
        });
    });
    function is_dress(dress_id){
        $.ajax({
            type : "post",
            url: baseurl+"index.php/dress/dress",
            data: {'dress_id':dress_id},
            dataType:"JSON",
            success: function (msg){
                if(msg.status==1){
                    layer.msg(msg.info);
                    window.location.href=window.location.href;
                }
            }
        })
    }
</script>
<!--]] user -->
<!-- coypright [[-->
<?php $this->load->view('common/footer');?>
<!--]] coypright -->
</body>
</html>
